package com.example.chapter5.controller;

import com.example.chapter5.entity.User;
import com.example.chapter5.util.JwtUtil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserController {
    @GetMapping("/login")
    public String login(User user){
        if (user!=null){
            return JwtUtil.createJwt(user);
        }
        throw new RuntimeException("Invalid credentials");
    }
    @GetMapping("/")
    public String index() {
        return "hello world";
    }
}
